Forward AI agent session/trace ids into outbound request headers#268
Open
sdairs wants to merge 1 commit into
Open
Forward AI agent session/trace ids into outbound request headers#268sdairs wants to merge 1 commit into
sdairs wants to merge 1 commit into
Conversation
Detect the calling AI agent's session id and W3C traceparent (via is-ai-agent 0.4.0) and forward them as `agent-session-id` and `traceparent` request headers on every outbound HTTP client, so backend telemetry can correlate a single agent session's calls. - Bump is-ai-agent 0.2.1 -> 0.4.0. - Add src/http.rs: the canonical reqwest client factory (client_builder) plus agent_headers(); user_agent.rs keeps its narrow job of building the User-Agent string. - Route all reqwest::Client::builder() sites (Cloud client, OAuth, updater, version manager) through crate::http::client_builder() so coverage is uniform and future builders inherit it. No clickhouse-cloud-api change: default headers ride the client we hand it. - Tests: pure-logic header-builder unit tests + a wiremock subprocess test asserting both headers land on the wire. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #267
What
Propagate the calling AI agent's session id and traceparent into outbound request headers, so backend telemetry can correlate every
clickhousectlcall made within a single agent session/conversation.Header names the backend looks for:
agent-session-id←Agent::session_idtraceparent←Agent::traceparent(raw W3C value)How
is-ai-agent0.2.1→0.4.0for the newAgent::session_id/Agent::traceparentfields.src/http.rsmodule — the canonical place to construct outboundreqwestclients. It ownsclient_builder()(pre-applies theUser-Agentand the agent default headers) andagent_headers().user_agent.rskeeps its narrow job of building just theUser-Agentstring.reqwest::Client::builder()sites throughcrate::http::client_builder()— not just the Cloud API client, but also OAuth, the self-updater, and the version manager (they all hit a clickhouse.com property in some way). This makes the builder the single source of truth, so future builders inherit the headers automatically.clickhouse-cloud-apichange needed: its client is built from thereqwest::Clientwe hand it inCloudClient::new(), and default headers ride along on every request (management API + SQL query paths).HeaderValue::from_str(..).ok()since session ids are opaque vendor strings.Tests
http.rs(both ids, neither, each alone, invalid value dropped, builder smoke).agent_session_and_trace_headers_are_forwarded) asserting both headers land on the wire when running under a detected agent.cargo test -p clickhousectlandcargo clippy --all-targetsare clean.🤖 Generated with Claude Code
Note
Low Risk
Additive telemetry headers on outbound HTTP with no auth or request-body changes; behavior is unchanged when no agent is detected.
Overview
When
clickhousectlruns under a detected coding agent, outbound HTTP now carriesagent-session-idandtraceparent(fromis-ai-agent0.4.0) so backend telemetry can tie CLI calls to one agent run.A new
httpmodule exposesclient_builder(), which applies the existingUser-Agentplus those default headers. Cloud OAuth, the Cloud API client, self-update, and version-manager downloads/probes all build clients through it instead of ad hocreqwest::Client::builder()calls.Invalid header values are skipped rather than failing the client build. Coverage includes unit tests for header construction and a wiremock subprocess test that asserts both headers on a real
cloud org listrequest when agent env vars are set.Reviewed by Cursor Bugbot for commit 8e969f1. Bugbot is set up for automated code reviews on this repo. Configure here.